import java.util.*;
import java.sql.*;
/**
 * scanner is System.in by default
 */
public class GoldfishReader {
    public static Scanner scanner = new Scanner(System.in);

    public static void changeScanner(Scanner newScanner){
        if(newScanner!=null){
            scanner.close();
            scanner=newScanner;
        }
    }
    public static int readInt(String prompt) {
        int value ;
        while (true){
            try {
                System.out.print(prompt);
                value = scanner.nextInt();
                return  value;
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请重新输入整数。");
            }
            finally {
                scanner.nextLine();
            }
        }
    }
    public static double readDouble(String prompt) {
        double value = 0;
        while (true){
            try {
                System.out.print(prompt);
                value = scanner.nextDouble();
                break;
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请重新输入小数。");
                scanner.nextLine();
            }
        }
        return value;
    }
    public static String readString(String prompt) {
        String value;
        while (true){
            try {
                System.out.print(prompt);
                value = scanner.nextLine();
                break;
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请重新输入小数。");
            }
        }
        return value;
    }
    public static String readString(String prompt, boolean split){
        if(split)
            return readString(prompt).split(" ")[0];
        else
            return readString(prompt);
    }
}
